#
# jukuMagic Makefile for Linux
#

CXX=g++

#DEBUG=true

# You can change these on command-line

ifndef DEBUG
	DEBUG=false
endif
ifndef WX_CONFIG
	WX_CONFIG=wx-config
endif
ifndef PYTHON_CONFIG
	PYTHON_CONFIG=python2-config
endif
ifndef PYTHON
	PYTHON=python2
endif

#WX_CONFIG=/usr/bin/wx-config
#PYTHON_CONFIG=/usr/bin/python-config
#PYTHON=/usr/bin/python

#WX_CONFIG=/usr/bin/wx-config
#PYTHON_CONFIG=/usr/local/bin/python-config

ifeq ($(DEBUG),true)
	CFLAGS=-Wall -g -O0 -DwxDEBUG_LEVEL=2 `$(WX_CONFIG) --debug --cxxflags` `$(PYTHON_CONFIG) --cflags`
	LDFLAGS=-g `$(WX_CONFIG) --debug --libs` `$(PYTHON_CONFIG) --libs`
else
	# Might be a good idea to set -DwxDEBUG_LEVEL=0
	#CFLAGS=-Wall -O2 -DwxDEBUG_LEVEL=1 `$(WX_CONFIG) --cxxflags` `$(PYTHON_CONFIG) --cflags`
	CFLAGS=-Wall -O2 `$(WX_CONFIG) --cxxflags` `$(PYTHON_CONFIG) --cflags`
	LDFLAGS= `$(WX_CONFIG) --libs` `$(PYTHON_CONFIG) --libs`
endif

SOURCES=jukuapp.cpp jukuframe.cpp boardwindow.cpp jukuobject.cpp xml.cpp\
		project.cpp board.cpp objectcontainer.cpp footprint.cpp boardpoint.cpp\
		component.cpp rect.cpp pin.cpp jumperwire.cpp settings.cpp arc.cpp\
		line.cpp footprintlibrarynode.cpp footprintlibrary.cpp flistbox.cpp\
		cut.cpp preferencesdialog.cpp projectsettingsdialog.cpp\
		netlist.cpp net.cpp ratsnest.cpp narrowcut.cpp strfnd.cpp\
		netcomponent.cpp netcomponenttable.cpp nettable.cpp componenttable.cpp\
		pythonapi.cpp pyjuku.cpp pyfootprint.cpp
TIXMLSOURCES=tinyxml/tinyxml.cpp tinyxml/tinyxmlerror.cpp tinyxml/tinyxmlparser.cpp
OBJECTS=$(SOURCES:.cpp=.o)
TIXMLOBJECTS=$(TIXMLSOURCES:.cpp=.o)
DOCS=doc/settings.txt doc/python_api_funcs.txt
AUTOGENERATED_STUFF=$(DOCS) settings.h settings.cpp

EXECUTABLE=jukumagic2

all: print_message $(EXECUTABLE) $(AUTOGENERATED_STUFF)

print_message:
	@echo 'Remember to export LD_LIBRARY_PATH=/usr/local/lib:$$LD_LIBRARY_PATH if you have libraries installed in there.'

$(EXECUTABLE): $(OBJECTS) $(TIXMLOBJECTS)
	#$(CXX) $(LDFLAGS) $(OBJECTS) $(TIXMLOBJECTS) -o $(EXECUTABLE)
	$(CXX) -o $(EXECUTABLE) $(OBJECTS) $(TIXMLOBJECTS) $(LDFLAGS)

settings.cpp: generate_settings.py
	$(PYTHON) generate_settings.py

settings.h: generate_settings.py
	$(PYTHON) generate_settings.py

doc/settings.txt: generate_settings.py
	$(PYTHON) generate_settings.py

doc/python_api_funcs.txt: list_python_api.py pyjuku.cpp
	$(PYTHON) list_python_api.py > doc/python_api_funcs.txt

.cpp.o:
	#$(CXX) $(CFLAGS) $< -c -o $@
	$(CXX) -c -o $@ $< $(CFLAGS)

$(OBJECTS): settings.h

clean:
	rm -f $(OBJECTS) $(EXECUTABLE) $(AUTOGENERATED_STUFF) $(TIXMLOBJECTS)

clean_juku:
	rm -f $(OBJECTS) $(EXECUTABLE) $(AUTOGENERATED_STUFF)

